package com.igeek.service;

import com.igeek.dao.Productdao;
import com.igeek.domain.Pagination;
import com.igeek.domain.Product;

import java.util.LinkedList;
import java.util.List;

public class Productservice {
    Productdao dao =new Productdao();
    public List<Product> gethotProducts() {
        return dao.gethotProducts();
    }

    public List<Product> getnewProducts() {
        return dao.getnewProducts();
    }

    public List<Product> findproductBycid(String cid) {
       return  dao.findproductBycid(cid);
    }

    public Pagination<Product> findProductsByCidPage(int nowPage, int i, String cid) {
        Pagination<Product> pagination =new Pagination<>();
        List<Product> data=dao.findData(nowPage,i,cid);
        pagination.setData(data);
        int record=dao.getCount(cid);
        //总页数
        int pages= (int) Math.ceil((double) record/i);
        pagination.setPage(nowPage);
        pagination.setCount(record);
        pagination.setTotalPage(pages);
        //设置分页条
        pagination.setBar();
        return pagination;
    }

    public Product getProductByPid(String pid) {
        return dao.getProductByPid(pid);
    }

    public List<Product> findHistoryProducts(String pids) {
        List<Product> products=new LinkedList<>();
        String[] srr=pids.split(",");
        for (String pid:srr){
            Product p=dao.findHistoryProducts(pid);
            products.add(p);
        }
        return products;
    }
}
